﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using log4net;
using RealState.BusinessObjects;
using RealState.BLL;

namespace RealState.W.uc
{
    public partial class ucNews : System.Web.UI.UserControl
    {
        private ILog log = LogManager.GetLogger("News");
        private News newsBO;
        private NewsBLL newsBLL;
        private List<News> listNews;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack) {
                LoadData();
            }
        }
        private void LoadData(){
            newsBO = new News();
            newsBLL = new NewsBLL();
            try
            {
                listNews = newsBLL.GetNewss().Where(b => b.RowNum <6).ToList();
                if (listNews.Count > 0)
                {
                    HyperLink1.NavigateUrl = "~/NewsPage.aspx?ID="+listNews[0].Id;
                    HyperLink1.Text = listNews[0].Title;
                    LiteralDescription.Text = listNews[0].Content;
                    listNews.RemoveAt(0);
                    RepeaterNews.DataSource = listNews;
                    RepeaterNews.DataBind();
                }
            }
            catch (Exception ex)
            {
                log.Debug(ex.Message);
            }
        }
    }
}